home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.000 / crossfir / crossfire-0.92.4.client / player.c < prev    next >
C/C++ Source or Header  |  1996-04-21  |  6KB  |  260 lines

  1. #include <client.h>
  2.  
  3. /* This file handles various player related functions.  This includes
  4.  * both things that operate on the player item, cpl structure, or
  5.  * various commands that the player issues.
  6.  *
  7.  *  does most of the work for sending messages to the server
  8.  *   Again, most of these appear self explanatory.  Most send a bunch of
  9.  *   commands like apply, examine, fire, run, etc.  This looks like it
  10.  *   was done by Mark to remove the old keypress stupidity I used. 
  11.  */
  12.  
  13. /* This translates the numeric direction id's into the actual direction
  14.  * commands.  This lets us send the actual command (ie, 'north'), which
  15.  * makes handling on the server side easier.
  16.  */
  17.  
  18. char *directions[9] = {"stay", "north", "northeast", "east", "southeast",
  19.         "south","southwest", "west", "northwest"};
  20.  
  21.  
  22. /*
  23.  *  Initialiazes player item, information is received from server
  24.  */
  25. void new_player (long tag, char *name, long weight, long face)
  26. {
  27.     cpl.ob->tag    = tag;
  28.     cpl.ob->nrof   = 1;
  29.     copy_name (cpl.ob->name, name);
  30.     cpl.ob->weight = (float) weight / 1000;
  31.     cpl.ob->face   = face;
  32. }
  33.  
  34. #if 0
  35. /* Following should not be needed any more */
  36.  
  37. static long lotso_keysyms[] = {
  38. #include "eatme.h"
  39. };
  40.  
  41.  
  42. #define NKEYSYMS (sizeof(lotso_keysyms)/sizeof(long))
  43.  
  44. void SendKeyConversion(TcpSocket conn)
  45. {
  46.   int i;
  47.   long kc,ks;
  48.   ArgList msg;
  49.  
  50. /*  printf("skc\n");*/
  51.   msg = ArgList_create();
  52.   ArgList_addLong(msg,STRINGCOMMAND);
  53.   ArgList_addString(msg,"keyconversion");
  54.   ArgList_addLong(msg,NKEYSYMS);
  55.   for(i=0;i<NKEYSYMS;i++) {
  56.     ks = lotso_keysyms[i];
  57.     kc = display_ks2kc(ks);
  58.     ArgList_addLong(msg,ks);
  59.     ArgList_addLong(msg,kc);
  60.   }
  61.   ArgList_send(conn,msg);
  62.   ArgList_destroy(msg);
  63. /*  printf("skc-done%d\n",NKEYSYMS);*/
  64. }
  65.  
  66.  
  67. void client_send_keypress(unsigned int keycode,unsigned long keysym,char key)
  68. {
  69.   ArgList msg;
  70.  
  71.   msg = ArgList_create();
  72.   ArgList_addLong(msg,STRINGCOMMAND);
  73.   ArgList_addString(msg,"keypress");
  74.   ArgList_addLong(msg,keycode);
  75.   ArgList_addLong(msg,keysym);
  76.   ArgList_addLong(msg,key);
  77.   ArgList_send(conns[0],msg);
  78.   ArgList_destroy(msg);
  79. }
  80.  
  81. void client_send_keyrelease(unsigned int keycode,unsigned long keysym,char key)
  82. {
  83.   ArgList msg;
  84.  
  85.   msg = ArgList_create();
  86.   ArgList_addLong(msg,STRINGCOMMAND);
  87.   ArgList_addString(msg,"keyrelease");
  88.   ArgList_addLong(msg,keycode);
  89.   ArgList_addLong(msg,keysym);
  90.   ArgList_addLong(msg,key);
  91.   ArgList_send(conns[0],msg);
  92.   ArgList_destroy(msg);
  93. }
  94. #endif
  95.  
  96. void client_send_apply (long tag)
  97. {
  98.     ArgList msg;
  99.  
  100.     msg = ArgList_create();
  101.     ArgList_addLong (msg, STRINGCOMMAND);
  102.     ArgList_addString (msg, "apply");
  103.     ArgList_addLong (msg, tag);
  104.     ArgList_send (conns[0],msg);
  105.     ArgList_destroy (msg);
  106. }
  107.  
  108. void client_send_examine (long tag)
  109. {
  110.     ArgList msg;
  111.  
  112.     msg = ArgList_create();
  113.     ArgList_addLong (msg, STRINGCOMMAND);
  114.     ArgList_addString (msg, "examine");
  115.     ArgList_addLong (msg, tag);
  116.     ArgList_send (conns[0],msg);
  117.     ArgList_destroy (msg);
  118. }
  119.  
  120. void client_send_move (long loc, long tag, long nrof)
  121. {
  122.     ArgList msg;
  123.  
  124.     msg = ArgList_create();
  125.     ArgList_addLong (msg, STRINGCOMMAND);
  126.     ArgList_addString (msg, "move");
  127.     ArgList_addLong (msg, loc);
  128.     ArgList_addLong (msg, tag);
  129.     ArgList_addLong (msg, nrof);
  130.     ArgList_send (conns[0],msg);
  131.     ArgList_destroy (msg);
  132. }
  133.  
  134.  
  135.  
  136. void move_player(int dir) {
  137.     ArgList msg;
  138.  
  139.     msg = ArgList_create();
  140.     ArgList_addLong (msg, STRINGCOMMAND);
  141.     ArgList_addString (msg, "command");
  142.     ArgList_addLong(msg, 0);
  143.     ArgList_addString(msg,directions[dir]);
  144.     ArgList_send (conns[0],msg);
  145.     ArgList_destroy (msg);
  146. }
  147.  
  148. /* Fires in a specified direction.  Note that direction 0 is a valid
  149.  * case - the fire is centered on the player.
  150.  */
  151.  
  152.  
  153. void stop_fire()
  154. {
  155.     ArgList msg;
  156.  
  157.     msg = ArgList_create();
  158.     ArgList_addLong (msg, STRINGCOMMAND);
  159.     ArgList_addString (msg, "command");
  160.     ArgList_addLong(msg,0);
  161.     ArgList_addString(msg,"fire_stop");
  162.     ArgList_send (conns[0],msg);
  163.     ArgList_destroy (msg);
  164. }
  165.  
  166. void stop_run()
  167. {
  168.     ArgList msg;
  169.  
  170.     msg = ArgList_create();
  171.     ArgList_addLong (msg, STRINGCOMMAND);
  172.     ArgList_addString (msg, "command");
  173.     ArgList_addLong(msg,0);
  174.     ArgList_addString(msg,"run_stop");
  175.     ArgList_send (conns[0],msg);
  176.     ArgList_destroy (msg);
  177. }
  178.  
  179. void fire_dir(int dir) {
  180.     ArgList msg;
  181.     char buf[MAX_BUF];
  182.  
  183.     msg = ArgList_create();
  184.     ArgList_addLong (msg, STRINGCOMMAND);
  185.     ArgList_addString (msg, "command");
  186.     ArgList_addLong(msg,0);
  187.     sprintf(buf,"fire %d\n", dir);
  188.     ArgList_addString(msg,buf);
  189.     ArgList_send (conns[0],msg);
  190.     ArgList_destroy (msg);
  191. }
  192.  
  193. void run_dir(int dir) {
  194.     ArgList msg;
  195.     char buf[MAX_BUF];
  196.  
  197.     msg = ArgList_create();
  198.     ArgList_addLong (msg, STRINGCOMMAND);
  199.     ArgList_addString (msg, "command");
  200.     ArgList_addLong(msg,0);
  201.     sprintf(buf,"run %d\n", dir);
  202.     ArgList_addString(msg,buf);
  203.     ArgList_send (conns[0],msg);
  204.     ArgList_destroy (msg);
  205. }
  206.  
  207. void send_command(char *command) {
  208.     ArgList msg;
  209.  
  210.     msg = ArgList_create();
  211.     ArgList_addLong (msg, STRINGCOMMAND);
  212.     ArgList_addString (msg, "command");
  213.     ArgList_addLong(msg, cpl.count);
  214.     ArgList_addString(msg,command);
  215.     ArgList_send (conns[0],msg);
  216.     ArgList_destroy (msg);
  217.     cpl.count=0;
  218. }
  219.  
  220. /* This is an extended command (ie, 'who, 'whatever, etc).  In general,
  221.  * we just send the command to the server, but there are a few that
  222.  * we care about (bind, unbind)
  223.  */
  224.  
  225. void extended_command(char *command) {
  226.     ArgList msg;
  227.     char *cp = command, *cpnext;
  228.  
  229.     if ((cpnext = strchr(cp, ' '))!=NULL)
  230.     *cpnext++ = '\0';
  231.  
  232.  
  233.     if (!strcmp(cp, "bind"))
  234.     bind_key(cpnext);
  235.     else if (!strcmp(cp,"unbind"))
  236.     unbind_key(cpnext);
  237.     else if (!strcmp(cp,"showicons"))
  238.     set_show_icon (cpnext);
  239.     else if (!strcmp(cp,"showweight"))
  240.     set_show_weight (cpnext);
  241.     else if (!strcmp(cp,"scroll"))
  242.     set_scroll(cpnext);
  243.     else if (!strcmp(cp,"inv")) /* inventory command is sended to server
  244.                    for debugging purposes */
  245.     print_inventory (cpl.ob);
  246.     else {
  247.     /* reconstruct the string */
  248.     if (cpnext) *(--cpnext) = ' ';
  249.  
  250.     msg = ArgList_create();
  251.     ArgList_addLong (msg, STRINGCOMMAND);
  252.     ArgList_addString (msg, "command");
  253.     ArgList_addLong(msg,0);
  254.     ArgList_addString(msg,cp);
  255.     ArgList_send (conns[0],msg);
  256.     ArgList_destroy (msg);
  257.     }
  258. }
  259.  
  260.